package com.mainaer.wjokhttp;

import com.mainaer.wjokhttp.comment.BaseResponse;
import com.mainaer.wjokhttp.model.MovieListResponse;
import com.mainaer.wjokhttp.comment.OkUtils;
import com.mainaer.wjokhttp.controller.MovieListController;
import com.mainaer.wjoklib.okhttp.OKHttpConfig;
import com.mainaer.wjoklib.okhttp.OKHttpManager;
import com.mainaer.wjoklib.okhttp.exception.OkHttpError;
import com.mainaer.wjoklib.okhttp.utils.WLog;

import org.junit.Before;
import org.junit.Test;

import okhttp3.logging.HttpLoggingInterceptor;

public class MovieControllerTest {

    private MovieListController movieListController;

    @Before
    public void init() {

        // 程序初始化时，初始okhttp配置
        OKHttpConfig OKHttpConfig = new OKHttpConfig.Builder()
                .setBaseResponseClass(BaseResponse.class)
                .setLogLevel(HttpLoggingInterceptor.Level.BODY)// log level
                .setConnectTimeout(10) // connect time out
                .setReadTimeout(10) // read time out
                .setWriteTimeout(10) // write time out
                .setCacheTime(1000) // cache time
                .build();
        OKHttpManager.init(OKHttpConfig);

        movieListController = new MovieListController(new MovieListController.MovieListListener() {
            @Override
            public void onLoadMovieListSuccess(MovieListResponse loadResponse) {
                WLog.d(OkUtils.object2Json(loadResponse));
            }

            @Override
            public void onLoadMovieListFail(OkHttpError e) {
                WLog.d(e.getMessage());
            }
        });
    }

    @Test
    public void loadMovieList(){
        movieListController.loadMovieList("harry", 1);
    }
}
